<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Think\Controller;
use Admin\Service\SheetService;


/**
 * 谱单控制器
 * @author Administrator
 *
 */
class ScoreSheetController extends AdminController {

    public function index()
    {
        $map = array(
            'score_id' => array('in', I('score_id')),
            'is_delete' => 0
        );

    
        $list   = $this->lists('ScoreSheet', $map);
    
        $service = new SheetService();
        $list = $service->listByIds($list);
        $this->assign('_list', $list);
        $this->assign('scoreId', I('score_id'));
        $this->assign('_condition', I('post.'));
        $this->meta_title = '谱单信息';
        $this->display();
    
    
    }
   
    public function del($score_id = 0){
    
        $id = array_unique((array)I('id',0));
        $count = count($id);

        $id = is_array($id) ? implode(',',$id) : $id;
        if (empty($id)) {
            $this->error('请选择要操作的数据!');
        }
        $map = array(
            'score_id' => $score_id,
            'sheet_id' => array('in', $id)
        );
        $data = array(
            'is_delete' => 1
        );

        $res = M('ScoreSheet')->where($map)->save($data);
        if($res){
            //谱单曲谱数 -n
            M('Score')->where(array('id'=>$score_id))->setDec('sheet_count', $count);

            $this->success('删除成功');
        } else {
            $this->error('删除失败！');
        }
    }
}
